﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using CommonWFLibrary;
using System.IO;
using DTBuilderLib;

namespace DeepTalkWF
{
    /// <summary>
    /// Copy over the silverlight infrastructure files to the final spot. Make sure everything is setup
    /// to go for a "click" so the user can view the resulting conference.
    /// </summary>
	public partial class CopyOverWebSite: LongRunningActivityBase
	{
		public CopyOverWebSite()
		{
			InitializeComponent();
            TimesToRetry = 10;
		}

        /// <summary>
        /// The location where the DZ image was built
        /// </summary>
        public string WebSiteBaseDirectory
        {
            get { return (string)GetValue(WebSiteBaseDirectoryProperty); }
            set { SetValue(WebSiteBaseDirectoryProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WebSiteBaseDirectory.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WebSiteBaseDirectoryProperty =
            DependencyProperty.Register("WebSiteBaseDirectory", typeof(string), typeof(CopyOverWebSite), new PropertyMetadata(null));

        /// <summary>
        /// Title of the meeting - will become title of web page
        /// </summary>
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(CopyOverWebSite), new PropertyMetadata(""));

        /// <summary>
        /// Args we pass in to the long running activity
        /// </summary>
        [Serializable]
        public class Args
        {
            public DirectoryInfo _dir;
            public string _title;
        }

        [LongRunningGatherArguments]
        public Args Gather()
        {
            Args r = new Args();
            r._dir = new DirectoryInfo(WebSiteBaseDirectory);
            r._title = Title;
            return r;
        }

        [LongRunningMethod]
        public static void Run(Args a)
        {
            FileInfo startPage = WebSiteBuilder.CreateWebSite(a._dir, a._title + " - DeepTalk");
        }
	}
}
